[Python]Xml add a node from another xml document

Posted by michele on Stack Overflow See other posts from Stack Overflow or by michele
Published on 2010-05-25T14:38:13Z Indexed on 2010/05/25 14:41 UTC
Read the original article Hit count: 400

Filed under:
|
|
|

Hi, I have two xml file: 1)model.xml 2)projectionParametersTemplate.xml

I want to extract from 1) Algorithm Node with his child and put it in 2)

I have wrote this code but it doesn't function.

from xml.dom.minidom import Document
from xml.dom import minidom      
xmlmodel=minidom.parse("/home/michele/Scrivania/d/model.xml")
xmltemplate=minidom.parse("/home/michele/Scrivania/d/projectionParametersTemplate.xml")

for Node in xmlmodel.getElementsByTagName("Algorithm"):
     print "\nNode: "+str(Node)
     for Node2 in xmltemplate.getElementsByTagName("ProjectionParameters"):
          print "\nNode2: "+str(Node2)
          Node2.appendChild(Node)

This is model.xml link text

This is projectionParametersTemplate.xml link text

Thanks a lot.

© Stack Overflow or respective owner

Related posts about python

Related posts about Xml